package cn.tedu.cwfw.comment.controller;

import cn.tedu.cwfw.base.response.JsonResult;
import cn.tedu.cwfw.comment.pojo.dto.CommentQuery;
import cn.tedu.cwfw.comment.pojo.dto.SaveCommentFrom;
import cn.tedu.cwfw.comment.pojo.vo.CommentVO;
import cn.tedu.cwfw.comment.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/cwfw/cutecircle/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    /**
     * 添加评论
     * @param saveComment 评论信息
     */
    @GetMapping("saveComment")
    public JsonResult saveComment(SaveCommentFrom saveComment){
        log.debug("创建评论请求,入参:{}",saveComment);
        commentService.saveComment(saveComment);
        return JsonResult.ok();
    }

    /**
     * 删除评论
     * @param id 评论id
     */
    @PostMapping("deleteComment/{id}")
    public JsonResult deleteComment(@PathVariable Long id){
        log.debug("删除评论请求,入参:{}",id);
        commentService.deleteComment(id);
        return JsonResult.ok();
    }

    /**
     * 点赞评论
     * @param id 评论id
     */
    @PostMapping("likeComment/{id}")
    public JsonResult likeComment(@PathVariable Long id){
        log.debug("点赞评论请求,入参:{}",id);
        commentService.likeComment(id);
        return JsonResult.ok();
    }

    /**
     * 获取评论
     * @param commentQuery 查询条件
     */
    @GetMapping("getComment")
    public JsonResult getComment(CommentQuery commentQuery){
        log.debug("获取评论请求,入参:{}",commentQuery);
        List<CommentVO> list = commentService.getComment(commentQuery);
        log.debug("获取评论请求,入参:{},出参:{}",commentQuery,list);
        return JsonResult.ok(list);
    }
}
